package top.api.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

public enum CommonStatusEnum {
    success(0,"正常"),
    error(1,"异常");

    /**
     * 标记数据库存的值是code
     */
    @EnumValue
    @JsonValue
    private final int code;

    /**
     * 标记前端展示、已经更新传的值
     */
    private final String status;

    CommonStatusEnum(int code, String status) {
        this.code = code;
        this.status = status;
    }

    public int getCode() {
        return code;
    }

    public String getStatus() {
        return status;
    }

    public static CommonStatusEnum getCommonStatEnumByCode(int code) {
        for (CommonStatusEnum commonStatusEnum : CommonStatusEnum.values()) {
            if (commonStatusEnum.getCode() == code) {
                return commonStatusEnum;
            }
        }
        throw new RuntimeException("status只能是0/1");
    }
}
